## Train on HCP, test on ABCD

### Compute functional similarity matrix between HCP training subjects and the selected AA and WA in ABCD data

```bash
work_dir=/home/jingweil/storage/MyProject/fairAI/cross_ABCD_HCP/mat/FSM/no_reg/HCP_to_ABCD/logs
mkdir -p $work_dir
jname=HCP_to_ABCD_FSM
cmd="matlab -nodesktop -nojvm -nodisplay -r \" cd /home/jingweil/storage/MyProject/fairAI/ABCD_race/scripts/Unfairness_ABCD_process; ABCD_addpath; HCP_to_ABCD_FSM_wrap(fullfile('/home/jingweil/storage/MyProject/fairAI/cross_ABCD_HCP/mat/FSM/no_reg/HCP_to_ABCD'),  [], [], [], [], [], [], fullfile('/home/jingweil/storage/MyProject/fairAI/HCP_race/mat/combine_AA_matchedWA_others_rm_AA_outliers18'), 400, fullfile('/home/jingweil/storage/MyProject/fairAI/ABCD_race/mat/matchANDsplit/20200719/sel_AAWA_pass_rs_pass_pheno.mat')); exit; \" "
$CBIG_CODE_DIR/setup/CBIG_pbsubmit -cmd "$cmd" -walltime 20:00:00 -mem 60G -ncpus 4 -name $jname -joberr $work_dir/$jname.err -jobout $work_dir/$jname.out
```

### Predict behavioral scores of ABCD subjects using KRR models trained on HCP dataset

```bash
../cross-datasets/HCP_to_ABCD/HCP_KRR_test_ABCD_AAWA.sh
```

### Predictable behaviors (tested across all ABCD subjects)

1. metric: predictive COD
   
```matlab
proj_dir = '/home/jingweil/storage/MyProject/fairAI';
HCP_KRR_test_ABCD_predictable_behavior(...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'mat', 'predictability', 'HCP_to_ABCD', 'pCOD_no_reg.mat'), ...
    fullfile(proj_dir, 'HCP_race', 'trained_model', 'split_948sub_AA_matchedWA_rm_AA_outliers18', 'outputs', 'l2_0_20_opt_pCOD_no_reg'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'models', 'KRR', 'no_reg', 'HCP_to_ABCD'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'mat', 'FSM', 'no_reg', 'HCP_to_ABCD'), 400, 1000, 'predictive_COD')
```

2. metric: Pearson's correlation

```matlab
proj_dir = '/home/jingweil/storage/MyProject/fairAI';
HCP_KRR_test_ABCD_predictable_behavior(...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'mat', 'predictability', 'HCP_to_ABCD', 'corr_no_reg.mat'), ...
    fullfile(proj_dir, 'HCP_race', 'trained_model', 'split_948sub_AA_matchedWA_rm_AA_outliers18', 'outputs', 'l2_0_20_opt_pCOD_no_reg'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'models', 'KRR', 'no_reg', 'HCP_to_ABCD'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'mat', 'FSM', 'no_reg', 'HCP_to_ABCD'), 400, 1000, 'corr')
```

### Plot accuracies across all subjects

1. metric: predictive COD

```matlab
proj_dir = '/home/jingweil/storage/MyProject/fairAI';
HCP_to_ABCD_violin_allsubj( ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'models', 'KRR', 'no_reg', 'HCP_to_ABCD'), 'predictive_COD', ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'figures', 'KRR', 'no_reg', 'HCP_to_ABCD'), 'pCOD_allsubj', 400, ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'scripts', 'lists', 'HCP_behavior.txt'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'scripts', 'lists', 'ABCD_colloquial.txt'))
```

2. metric: Pearson's correlation

```matlab
proj_dir = '/home/jingweil/storage/MyProject/fairAI';
HCP_to_ABCD_violin_allsubj( ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'models', 'KRR', 'no_reg', 'HCP_to_ABCD'), 'corr', ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'figures', 'KRR', 'no_reg', 'HCP_to_ABCD'), 'corr_allsubj', 400, ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'scripts', 'lists', 'HCP_behavior.txt'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'scripts', 'lists', 'ABCD_colloquial.txt'))
```

### Compare prediction accuracy between AA and WA of test ABCD subjects

1. Accuracy metric: predictive COD
   
```matlab
proj_dir = '/home/jingweil/storage/MyProject/fairAI';
HCP_to_ABCD_KRR_acc_AAvsWA(...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'models', 'KRR', 'no_reg', 'HCP_to_ABCD'), 'predictive_COD', ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'mat', 'AAvsWA', 'no_reg', 'HCP_to_ABCD', 'pCOD.mat'), 400, ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'scripts', 'lists', 'HCP_behavior.txt'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'scripts', 'lists', 'ABCD_behavior.txt'))
```

2. Accuracy metric: Pearson's correlation

```matlab
proj_dir = '/home/jingweil/storage/MyProject/fairAI';
HCP_to_ABCD_KRR_acc_AAvsWA(...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'models', 'KRR', 'no_reg', 'HCP_to_ABCD'), 'corr', ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'mat', 'AAvsWA', 'no_reg', 'HCP_to_ABCD', 'corr.mat'), 400, ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'scripts', 'lists', 'HCP_behavior.txt'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'scripts', 'lists', 'ABCD_behavior.txt'))
```

### Permutation test for the significancy of the accuracy difference

1. Accuracy metric: predictive COD

```matlab
proj_dir = '/home/jingweil/storage/MyProject/fairAI';
HCP_to_ABCD_PermTest_AAvsWA(...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'mat', 'AAvsWA', 'no_reg', 'HCP_to_ABCD', 'stats_pCOD_AAvsWA.mat'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'mat', 'AAvsWA', 'no_reg', 'HCP_to_ABCD', 'pCOD.mat'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'models', 'KRR', 'no_reg', 'HCP_to_ABCD'), 400, 'predictive_COD', ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'scripts', 'lists', 'HCP_behavior.txt'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'scripts', 'lists', 'ABCD_behavior.txt'))
```

2. Acuracy metric: Pearson's correlation

```matlab
proj_dir = '/home/jingweil/storage/MyProject/fairAI';
HCP_to_ABCD_PermTest_AAvsWA(...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'mat', 'AAvsWA', 'no_reg', 'HCP_to_ABCD', 'stats_corr_AAvsWA.mat'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'mat', 'AAvsWA', 'no_reg', 'HCP_to_ABCD', 'corr.mat'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'models', 'KRR', 'no_reg', 'HCP_to_ABCD'), 400, 'corr', ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'scripts', 'lists', 'HCP_behavior.txt'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'scripts', 'lists', 'ABCD_behavior.txt'))
```

### Plot the difference

1. Accuracy metric: predictive COD

```matlab
proj_dir = '/home/jingweil/storage/MyProject/fairAI';
HCP_to_ABCD_AAvsWA_violin( ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'mat', 'AAvsWA', 'no_reg', 'HCP_to_ABCD', 'pCOD.mat'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'mat', 'AAvsWA', 'no_reg', 'HCP_to_ABCD', 'stats_pCOD_AAvsWA.mat'), 'predictive_COD', ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'figures', 'KRR', 'no_reg', 'HCP_to_ABCD', 'pCOD_AAvsWA.png'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'scripts', 'lists', 'ABCD_behavior.txt'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'scripts', 'lists', 'ABCD_colloquial.txt'))
```

2. Accuracy metric: Pearson's correlation

```matlab
proj_dir = '/home/jingweil/storage/MyProject/fairAI';
HCP_to_ABCD_AAvsWA_violin( ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'mat', 'AAvsWA', 'no_reg', 'HCP_to_ABCD', 'corr.mat'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'mat', 'AAvsWA', 'no_reg', 'HCP_to_ABCD', 'stats_corr_AAvsWA.mat'), 'corr', ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'figures', 'KRR', 'no_reg', 'HCP_to_ABCD', 'corr_AAvsWA.png'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'scripts', 'lists', 'ABCD_behavior.txt'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'scripts', 'lists', 'ABCD_colloquial.txt'))
```


## Train on ABCD, test on HCP

### Compute functional similarity matrix between ABCD training subjects and all HCP subjects

```bash
../cross-datasets/ABCD_to_HCP/ABCD_to_HCP_FSM.sh
```

### Predict behavioral scores of ABCD subjects using KRR models trained on HCP dataset

```bash
../cross-datasets/ABCD_to_HCP/ABCD_KRR_test_HCP.sh
```

### Predictable behaviors (tested across all HCP subjects)

1. metric: predictive COD

```matlab
proj_dir = '/home/jingweil/storage/MyProject/fairAI';
ABCD_KRR_test_HCP_predictable_behavior( ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'mat', 'predictability', 'ABCD_to_HCP', 'pCOD_no_reg.mat'), ...
    fullfile(proj_dir, 'ABCD_race', 'mat', 'matchANDsplit', '20200719'), ...
    fullfile(proj_dir, 'ABCD_race', 'models', 'KRR', '20200721', 'no_reg'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'models', 'KRR', 'no_reg', 'ABCD_to_HCP'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'mat', 'FSM', 'no_reg', 'ABCD_to_HCP'), 1000, ...
    'predictive_COD', [], [], [], [], ...
    fullfile(proj_dir, 'HCP_race', 'trained_model', 'split_948sub_AA_matchedWA_rm_AA_outliers18', 'outputs', 'l2_0_20_opt_pCOD_no_reg') )
```

2. metric: Pearson's correlation

```matlab
proj_dir = '/home/jingweil/storage/MyProject/fairAI';
ABCD_KRR_test_HCP_predictable_behavior( ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'mat', 'predictability', 'ABCD_to_HCP', 'corr_no_reg.mat'), ...
    fullfile(proj_dir, 'ABCD_race', 'mat', 'matchANDsplit', '20200719'), ...
    fullfile(proj_dir, 'ABCD_race', 'models', 'KRR', '20200721', 'no_reg'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'models', 'KRR', 'no_reg', 'ABCD_to_HCP'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'mat', 'FSM', 'no_reg', 'ABCD_to_HCP'), 1000, ...
    'corr', [], [], [], [], ...
    fullfile(proj_dir, 'HCP_race', 'trained_model', 'split_948sub_AA_matchedWA_rm_AA_outliers18', 'outputs', 'l2_0_20_opt_pCOD_no_reg') )
```

### Plot accuracies across all subjects

1. metric: predictive COD

```matlab
proj_dir = '/home/jingweil/storage/MyProject/fairAI';
ABCD_to_HCP_violin_allsubj( ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'models', 'KRR', 'no_reg', 'ABCD_to_HCP'), 'predictive_COD', ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'figures', 'KRR', 'no_reg', 'ABCD_to_HCP'), 'pCOD_allsubj', ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'scripts', 'lists', 'ABCD_behavior.txt'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'scripts', 'lists', 'HCP_colloquial.txt'))
```

2. metric: Pearson's correlation

```matlab
proj_dir = '/home/jingweil/storage/MyProject/fairAI';
ABCD_to_HCP_violin_allsubj( ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'models', 'KRR', 'no_reg', 'ABCD_to_HCP'), 'corr', ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'figures', 'KRR', 'no_reg', 'ABCD_to_HCP'), 'corr_allsubj', ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'scripts', 'lists', 'ABCD_behavior.txt'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'scripts', 'lists', 'HCP_colloquial.txt'))
```


### Compare prediction accuracy between AA and WA of test ABCD subjects

1. metric: Predictive COD

```matlab
proj_dir = '/home/jingweil/storage/MyProject/fairAI';
ABCD_to_HCP_KRR_acc_AAvsWA(...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'models', 'KRR', 'no_reg', 'ABCD_to_HCP'), 'predictive_COD', ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'mat', 'AAvsWA', 'no_reg', 'ABCD_to_HCP', 'pCOD.mat'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'scripts', 'lists', 'ABCD_behavior.txt'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'scripts', 'lists', 'HCP_behavior.txt'))
```

2. metric: Pearson's correlation

```matlab
proj_dir = '/home/jingweil/storage/MyProject/fairAI';
ABCD_to_HCP_KRR_acc_AAvsWA(...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'models', 'KRR', 'no_reg', 'ABCD_to_HCP'), 'corr', ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'mat', 'AAvsWA', 'no_reg', 'ABCD_to_HCP', 'corr.mat'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'scripts', 'lists', 'ABCD_behavior.txt'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'scripts', 'lists', 'HCP_behavior.txt'))
```

### Permutation test for the significancy of the accuracy difference

1. metric: predictive COD

```matlab
proj_dir = '/home/jingweil/storage/MyProject/fairAI';
ABCD_to_HCP_PermTest_AAvsWA( ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'mat', 'AAvsWA', 'no_reg', 'ABCD_to_HCP', 'stats_pCOD_AAvsWA.mat'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'mat', 'AAvsWA', 'no_reg', 'ABCD_to_HCP', 'pCOD.mat'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'models', 'KRR', 'no_reg', 'ABCD_to_HCP'), 'predictive_COD', ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'scripts', 'lists', 'ABCD_behavior.txt'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'scripts', 'lists', 'HCP_behavior.txt'))
```

2. metric: Pearson's correlation

```matlab
proj_dir = '/home/jingweil/storage/MyProject/fairAI';
ABCD_to_HCP_PermTest_AAvsWA( ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'mat', 'AAvsWA', 'no_reg', 'ABCD_to_HCP', 'stats_corr_AAvsWA.mat'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'mat', 'AAvsWA', 'no_reg', 'ABCD_to_HCP', 'corr.mat'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'models', 'KRR', 'no_reg', 'ABCD_to_HCP'), 'corr', ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'scripts', 'lists', 'ABCD_behavior.txt'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'scripts', 'lists', 'HCP_behavior.txt'))
```

### Plot the difference

1. metric: predictive COD

```matlab
proj_dir = '/home/jingweil/storage/MyProject/fairAI';
ABCD_to_HCP_AAvsWA_violin(...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'mat', 'AAvsWA', 'no_reg', 'ABCD_to_HCP', 'pCOD.mat'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'mat', 'AAvsWA', 'no_reg', 'ABCD_to_HCP', 'stats_pCOD_AAvsWA.mat'), ...
    'predictive_COD', fullfile(proj_dir, 'cross_ABCD_HCP', 'figures', 'KRR', 'no_reg', 'ABCD_to_HCP', 'pCOD_AAvsWA.png'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'scripts', 'lists', 'HCP_behavior.txt'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'scripts', 'lists', 'HCP_colloquial.txt'))
```

2. metric: Pearson's correlation

```matlab
proj_dir = '/home/jingweil/storage/MyProject/fairAI';
ABCD_to_HCP_AAvsWA_violin(...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'mat', 'AAvsWA', 'no_reg', 'ABCD_to_HCP', 'corr.mat'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'mat', 'AAvsWA', 'no_reg', 'ABCD_to_HCP', 'stats_corr_AAvsWA.mat'), ...
    'corr', fullfile(proj_dir, 'cross_ABCD_HCP', 'figures', 'KRR', 'no_reg', 'ABCD_to_HCP', 'corr_AAvsWA.png'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'scripts', 'lists', 'HCP_behavior.txt'), ...
    fullfile(proj_dir, 'cross_ABCD_HCP', 'scripts', 'lists', 'HCP_colloquial.txt'))
```